//AC Code
#include<bits/stdc++.h>
using namespace std;

struct Node{
    bool v=false;
    bool is_word=false;
    int next=0;
};

const int MAXN=1e6;
int n,tn=0,m;
Node t[MAXN][26];

int main(int argc,char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);

    #ifdef OITEST
        #define AS(c){if(!(c)){cerr<<"assert faild :"<<#c<<endl;return -1;}}
        AS(argc==3)
        cout<<argv[0]<<" "<<argv[1]<<" "<<argv[2]<<endl;
        ifstream ifile(argv[1]);
        ifstream afile(argv[2]);
        AS(ifile.is_open()==true)
        AS(afile.is_open()==true)
        stringstream ss;
        #define cin ifile
        #define cout ss
    #endif

    cin>>n;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        int now=0;
        for(int j=0;j<s.size()-1;j++){
            if (t[now][s[j]-'a'].next==0) {
                t[now][s[j]-'a'].next=++tn;
            }
            now=t[now][s[j]-'a'].next;
        }
        t[now][s[s.size()-1]-'a'].is_word=true;
    }
    cin>>m;
    for(int i=1;i<=m;i++){
        string s;
        cin>>s;
        int now=0;
        #ifdef OIPRINT
            // cout<<s<<endl;
            #define PRINTV(v)
        #endif
        for(int j=0;j<s.size()-1;j++){
            #ifdef OIPRINT
                PRINTV(j)
                PRINTV(now)
                PRINTV(t[now][s[j]-'a'].next)
            #endif
            if (t[now][s[j]-'a'].next==0) {
                cout<<"WRONG"<<endl;
                goto out;
            }
            now=t[now][s[j]-'a'].next;
        }
        if (!t[now][s[s.size()-1]-'a'].is_word) {
            cout<<"WRONG"<<endl;
            goto out;
        }
        if(t[now][s[s.size()-1]-'a'].v){
            cout<<"REPEAT"<<endl;
        }else{
            t[now][s[s.size()-1]-'a'].v=true;
            cout<<"OK"<<endl;
        }
        out:;
        #ifdef OITEST
            string cans;
            afile>>cans;
            string myans;
            ss>>myans;
            AS(myans==cans)
        #endif
    }
}